package com.xiaotao.verify;

import com.xiaotao.verify.utils.Image2Base64;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;

/**
 * @author xiaotao
 * @create 2023/2/28 17:24
 */
@Slf4j
@RestController
@RequestMapping("verify")
@AllArgsConstructor
public class VerifyController {
    private final HttpSession session;

    @RequestMapping("image")
    public Object getImage(HttpServletResponse response)throws Exception{
        VerifyCode code = new VerifyCode();
        BufferedImage image = code.getImage();
        String text = code.getText();
        String parse = Image2Base64.parse(image);
//        VerifyCode.output(image,response.getOutputStream());
        log.error("the code is {}",text);
        return parse;
    }
}
